<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/22
 * Time: 17:06
 */

header("Access-Control-Allow-Origin: *");
//PHP链接数据库
$serverName = '127.0.0.1';
$dbUser = 'root';
$dbPwd = '';
$dbName = 'zhiwophp';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $uphone = $_REQUEST["uphone"];
    $upwd = $_REQUEST["upwd"];
    $conn = new mysqli($serverName, $dbUser, $dbPwd, $dbName);
    mysqli_query($conn, 'set names utf8');//设置链接的字符集
    if ($conn->connect_error) {//链接失败
        $arr = array();
        $arr["status"] = 0;
        $arr["msg"] = "链接失败";
        print_r(json_encode($arr));
    } else {//链接成功
        $sql = "SELECT * FROM zhiwo WHERE uphone='".$uphone."'&&upwd='".$upwd."'";
        $res = $conn->query($sql);

        if ($res->num_rows>=1) {
            $arr = array();
            $arr["status"] = 1;
            $arr["msg"] = "登陆成功";
            print_r(json_encode($arr));
        } else {
            $arr = array();
            $arr["status"] = 0;
            $arr["msg"] = "用户名密码错误";
            print_r(json_encode($arr));
        }
    }
}else{
    $arr = array();
    $arr["status"] = 0;
    $arr["msg"] = "请选择post请求谢谢";
    print_r(json_encode($arr));
}